﻿//产品搜索
function sch_pro(obj,ver)
{
   var key=obj["keyword"].value;
   var url=(ver==1)?"productsen.asp":"products.asp";
   var clsid;
   if (obj["clsid"]==null) clsid=0;
   else clsid=obj["clsid"].value;
   clsid=(/^\d+$/.test(clsid))?clsid:0;
   key=key.replace("请输入关键字","");
   key=key.replace("Keyword","");
   //if (clsid==0 && key=="") return false;
   url=url+"?keyword="+escape(key)+"&amp;clsid="+clsid;
   location.href=url;
   return false;
}

//产品搜索 eng
function sch_pro_en(obj,ver)
{
   var key=obj["keyword"].value;
   var url=(ver==1)?"productsen.asp":"productsen.asp";
   var clsid;
   if (obj["clsid"]==null) clsid=0;
   else clsid=obj["clsid"].value;
   clsid=(/^\d+$/.test(clsid))?clsid:0;
   key=key.replace("Keywords","");
   //if (clsid==0 && key=="") return false;
   url=url+"?keyword="+escape(key)+"&amp;clsid="+clsid;
   location.href=url;
   return false;
}


//新闻搜索
function sch_news(obj,ver)
{
    var url=(ver==1)?"news_en.asp":"news.asp";
    var key=obj["keyword"].value;
    var clsid;
    if (obj["clsid"]==null) clsid=0;
    else clsid=obj["clsid"].value;
    clsid=(/^\d+$/.test(clsid))?clsid:0;
    if (clsid==0 && key=="") return false;
    url+="?clsid="+clsid+"&amp;keyword="+escape(key);
    location.href=url;
    return false;
}

//新闻搜索测试
function sch_news1(obj,ver)
{
    var url=(ver==1)?"news1.asp":"news1.asp";
    var key=obj["keyword"].value;
    var clsid;
    if (obj["clsid"]==null) clsid=0;
    else clsid=obj["clsid"].value;
    clsid=(/^\d+$/.test(clsid))?clsid:0;
    //if (clsid==0 && key=="") return false;
    url+="?clsid="+clsid+"&amp;keyword="+escape(key);
    location.href=url;
    return false;
}


//登陆验证
function chklogin(obj)
{
  var fm=obj;
  if (fm["username"].value=="" ){
      fm["username"].focus();
      alert("请输入用户名!");
      return false;
  }
  if (fm["userpass"].value==""){
      fm["userpass"].focus();
      alert("请输入密码!");
      return false;
  }
}
function chklogin_en(obj)
{
  var fm=obj;
  if (fm["username"].value=="" ){
      fm["username"].focus();
      alert("Please enter a user name!");
      return false;
  }
  if (fm["userpass"].value==""){
      fm["userpass"].focus();
      alert("Please enter a user name!");
      return false;
  }
}
//简介类，分页显示
var page=0;
var pageArr=new Array();

function initPage(objID,ver)
{
    var obj=document.getElementById(objID);
    if (obj==null) return;
    var tmp=obj.innerHTML;
    if (tmp=="") return;
	if (!tmp.match(/\[nextpage\]/i)) return;
    //处理<div page='page数字'></div>格式
    tmp=tmp.replace(/<div\s+[^>]*id=(['"])?page\d+\1[^>]*>/gi,"[NextPage]<div>");
    tmpArr=tmp.split(/\[nextpage\]/gi);
    if (tmp.match(/\[NEXTPAGE\]/i)){
        tmp="";
        for (var i=0;i<tmpArr.length;i++)
        {
           if (trim(tmpArr[i])!="") tmp+="<div id=\"page"+i+"\">"+tmpArr[i]+"</div>";
        }
    }
    obj.innerHTML=tmp;
    if (ver=="en"){
        GetPageArr_en(objID);    
    }
    else{
        GetPageArr(objID);    
    }
}

function GetPageArr(objID)
{
    var obj=document.getElementById(objID);
    var tmpArr=obj.getElementsByTagName("div");
    var tmp="";
    var tmp2="";
    var obj;
    for (var i=0;i<tmpArr.length;i++)
    {
        if ( /^page\d+$/i.test(tmpArr[i].id) )
        pageArr.push(tmpArr[i].id);
    }
    if (pageArr.length<2) return;
    for (var i=0;i<pageArr.length;i++)
    {
        if (i!=page){
            document.getElementById(pageArr[i]).style.display="none";
        }
        tmp2+="<option value=\""+i+"\">"+(i+1)+"</option>";
    }
    tmp2="&nbsp;<span class=\"go\">第<select id=\"selpage\" onchange=\"showPage(this.value);\">"+tmp2+"</select>页</span>";
    tmp="";
    tmp+="<div id=\"showpage\">";
    tmp+="<a href=\"javascript:void(0);\" onclick=\"showPage('pre');\">上一页</a>&nbsp;&nbsp;";
    tmp+="<a href=\"javascript:void(0);\" onclick=\"showPage('next');\">下一页</a>";
    tmp+=tmp2;
    tmp+="</div>";
    document.write(tmp);
}

function GetPageArr_en(objID)
{
    var obj=document.getElementById(objID);
    var tmpArr=obj.getElementsByTagName("div");
    var tmp="";
    var tmp2="";
    var obj;
    for (var i=0;i<tmpArr.length;i++)
    {
        if ( /^page\d+$/i.test(tmpArr[i].id) )
        pageArr.push(tmpArr[i].id);
    }
    if (pageArr.length<2) return;
    for (var i=0;i<pageArr.length;i++)
    {
        if (i!=page){
            document.getElementById(pageArr[i]).style.display="none";
        }
        tmp2+="<option value=\""+i+"\">"+(i+1)+"</option>";
    }
    tmp2="&nbsp;<span class=\"go\">Goto Page <select id=\"selpage\" onchange=\"showPage(this.value);\">"+tmp2+"</select></span>";
    tmp="";
    tmp+="<div id=\"showpage\">";
    tmp+="<a href=\"javascript:void(0);\" onclick=\"showPage('pre');\">Previous</a>&nbsp;&nbsp;";
    tmp+="<a href=\"javascript:void(0);\" onclick=\"showPage('next');\">Next</a>";
    tmp+=tmp2;
    tmp+="</div>";
    document.write(tmp);
}

function showPage(str)
{
   var tmp="";
   if (pageArr.length==0) return;
   if (/^\d+$/.test(str)==false){
       switch(str)
       {
            case "pre":page--;if (page<0) page=0;break;
            case "next":page++;if (page>pageArr.length-1) page=pageArr.length-1;break;    
       }
   }
   else{
        page=parseInt(str);
   }
    document.getElementById(pageArr[page]).style.display="";
    for (var i=0;i<pageArr.length;i++)
    {
        if (i!=page){
            document.getElementById(pageArr[i]).style.display="none";
        }
    }
    var sel=document.getElementById("selpage");
    for (var i=0;i<sel.length;i++)
    {
        if (sel[i].value==page) sel[i].selected="true";    
    }
    window.scrollTo(0,0);
}

//图片宽度处理
function art_fixImgWidth(objID,maxwidth)
{
   if (/^[1-9]\d*$/.test(maxwidth)==false) return;
   var maxwidth=parseInt(maxwidth);
   var panel=document.getElementById(objID);
   if (!panel) return;
   var obj=panel.getElementsByTagName("img");
   var tmp="";
   for (var i=0;i<obj.length;i++)
   {
       obj[i].style.maxWidth=maxwidth+"px";
       obj[i].onload=function(){
            var tmpImg=new Image();
            tmpImg.src=this.src;
            if (tmpImg.width>maxwidth) this.style.width=maxwidth+"px";
       }
   }
}

//下拉列表宽度限制的处理
function SelectFix(id,maxSize,maxWidth,margin,margin_old)
{
    var obj=document.getElementById(id);
    if (!obj) return;
    if (obj.tagName.toLowerCase()!="select") return;
	obj.style.width=maxWidth+"px";
    obj.onclick=function(){
         if (this.style.position!="absolute"){
             this.style.position="absolute";
             if (margin!="") this.style.margin=margin;
             this.style.width="auto";
             this.size=(this.length>maxSize)?maxSize:this.length;
			 this.style.zIndex=999;
         }
         else{
              this.style.position="static";
              if (margin_old!="") this.style.margin=margin_old;
              this.size=1;
              this.style.width=maxWidth+"px";
         }
    }
}

//二级菜单显示
function highNowCls(clsid)
{
    if (/^[1-9]\d*$/.test(clsid)==false) return;
    var obj=document.getElementById("cls"+clsid);
    if (!obj) return;
    obj.className += " cls_now";
    if (/^[1-9]\d*$/.test(obj.rel)==false) return;
    var p=document.getElementById("cls"+obj.rel);
    if (p) p.className += " cls_now_parent";
}

function DrawImage(ImgD,iwidth,iheight){    
    //参数(图片,允许的宽度,允许的高度)    
    var image=new Image();    
    image.src=ImgD.src;    
    if(image.width>0 && image.height>0){    
      if(image.width/image.height>= iwidth/iheight){    
          if(image.width>iwidth){      
              ImgD.width=iwidth;    
              ImgD.height=(image.height*iwidth)/image.width;    
          }else{    
              ImgD.width=image.width;      
              ImgD.height=image.height;    
          }    
      }else{    
          if(image.height>iheight){      
              ImgD.height=iheight;    
              ImgD.width=(image.width*iheight)/image.height;            
          }else{    
              ImgD.width=image.width;      
              ImgD.height=image.height;    
          }    
      }    
    }    
}   